﻿using Microsoft.AspNetCore.Mvc;
using RobosimAPI.Class;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace RobosimAPI.Controllers
{
	[Route("back/Api2/Client/themeList")]
	public class ThemeListController : ControllerBase
	{
		[HttpPost]
		public IActionResult GetThemeList([FromForm] ThemeModel model)
		{
			string sign = HttpContext.Request.Headers["Sign"].ToString();
			string date = HttpContext.Request.Headers["Request-Date"].ToString();
			if (string.IsNullOrEmpty(sign) || string.IsNullOrEmpty(date))
			{
				return Ok(new ErrorResponse() { status = -1, errmsg = "_ERROR_SIGN_" });
			}
            Account account = new Account(model.user_id);
			if(!account.SingnCheck(sign, date))
			{
				return Ok(new ErrorResponse() { status = -1, errmsg = "_ERROR_SIGN_" });
			}
			Theme[] themes=Theme.GetAllThemes();
			ThemeListResponse response = new ThemeListResponse();
			response.status=1;
			response.themeList=new List<ThemeListItem>();
			foreach(Theme theme in themes)
			{
				if (theme.IsVipTheme() && !account.IsVip())
				{
					continue;
				}
				response.themeList.Add(new ThemeListItem() { id = theme.Id, title = theme.Title, cover = theme.Cover, type = theme.Type, version = theme.Version });
			}
			return Ok(response);
		}
		public class ThemeModel
		{
			public int user_id { get; set; }
			public int region_id { get; set; }
		}
		public class ThemeListItem
		{
			public int id { get; set; }
			public string title { get; set; }
			public string cover { get; set; }
			public int type { get; set; }
			public string version { get; set; }
		}
		public class ThemeListResponse
		{
			public int status { get; set; }
			public List<ThemeListItem> themeList{ get; set; }
		}

	}
}
